﻿'========================================================================
'功能:公佈欄資料維護
'作者:andy
'日期: 2011/9/10
'========================================================================
Imports System.Data
Imports System.IO
Partial Class WFBillBoard
    Inherits BasePage
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then
            hiActualUID.Value = ActualUID
            hiUID.Value = UID
            hiDBName.Value = dbName
            If ChkProgramRight("2") = False Then
                btnInsert.Visible = False

            End If

            If ChkProgramRight("3") = False Then

                gvMain.Columns(0).Visible = False
            End If


        End If

    End Sub






    Protected Sub gvMain_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvMain.PageIndexChanging
        gvMain.SelectedIndex = -1
        gvMain.EditIndex = -1
    End Sub

    Protected Sub gvMain_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gvMain.RowCancelingEdit
        gvMain.SelectedIndex = -1
        gvMain.EditIndex = -1
    End Sub

 
    Private Sub GetData()
        Dim dt As DataTable
        Dim bbl As WorkFlow.BBL.WFBillBoardBBL = New WorkFlow.BBL.WFBillBoardBBL()
        dt = bbl.GetDataBillNo(txtBillNo.Text, hiDBName.Value)
        If dt.Rows.Count = 0 Then
            BlankData()
            Exit Sub
        End If

        txtBillNo.Text = dt.Rows(0)("BillNo").ToString
        txtSubject.Text = dt.Rows(0)("Subject").ToString
        txtURL.Text = dt.Rows(0)("URL").ToString
        txtTargetGroupID.Text = dt.Rows(0)("TargetGroupID").ToString
        lblTargetGroupName1.Text = dt.Rows(0)("TargetGroupName").ToString
        txtCrtGroupID.Text = dt.Rows(0)("CrtGroupID").ToString
        txtCrtGroupName.Text = dt.Rows(0)("CrtGroupName").ToString
        Try
            txtBegDate.Text = DateTime.Parse(dt.Rows(0)("BegDate").ToString).ToString("yyyy/MM/dd HH:mm ")
        Catch ex As Exception
            txtBegDate.Text = ""
        End Try
        Try
            txtEndDate.Text = DateTime.Parse(dt.Rows(0)("EndDate").ToString).ToString("yyyy/MM/dd HH:mm ")
        Catch ex As Exception
            txtEndDate.Text = ""

        End Try


        If dt.Rows(0)("Active").ToString.ToUpper = "TRUE" Then
            cbActive.Checked = True
        Else
            cbActive.Checked = False
        End If

        Try
            lblCrtDate2.Text = DateTime.Parse(dt.Rows(0)("CrtDate").ToString).ToString("yyyy/MM/dd HH:mm:ss ")
        Catch ex As Exception
            lblCrtDate2.Text = ""
        End Try
        Try
            lblModiDate2.Text = DateTime.Parse(dt.Rows(0)("ModiDate").ToString).ToString("yyyy/MM/dd HH:mm:ss ")
        Catch ex As Exception
            lblModiDate2.Text = ""

        End Try
        lblCrtName2.Text = dt.Rows(0)("CrtName").ToString

        lblModiName2.Text = dt.Rows(0)("ModiName").ToString
        lblModiUID.Text = dt.Rows(0)("ModiUID").ToString
        lblCrtUID.Text = dt.Rows(0)("CrtUID").ToString
        txtOrderBy.Text = dt.Rows(0)("OrderBy").ToString
    End Sub
    Private Sub BlankData()
        
        txtBillNo.Text = ""
        txtSubject.Text = ""
        txtURL.Text = ""
        txtTargetGroupID.Text = ""
        lblTargetGroupName1.Text = ""
        txtCrtGroupID.Text = ""
        txtCrtGroupName.Text = ""
        txtBegDate.Text = ""
        txtEndDate.Text = ""
        cbActive.Checked = False
        lblCrtDate2.Text = ""
        lblModiDate2.Text = ""
        lblCrtName2.Text = ""
        lblModiName2.Text = ""
        lblModiUID.Text = ""
        lblCrtUID.Text = ""
        txtOrderBy.Text = ""
    End Sub
    Protected Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        hiMode.Value = "Edit" ''編輯
        txtBillNo.Text = CType(sender, Button).CommandArgument.ToString()
        lbMode.Text = GetLocalResourceObject("EditMode")

        GetData() ''需找出原資料  
        mpInsert.Show()
    End Sub

    Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        lbMode.Text = GetLocalResourceObject("InsMode")

        hiMode.Value = "Ins"
        BlankData() ''清空畫面
        mpInsert.Show()
    End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim gBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
     
        ''======================================================================================================
        If txtTargetGroupID.Text <> "" Then
            If gBBL.GroupIDIsExist(txtTargetGroupID.Text, hiDBName.Value) = False Then
                ShowMessageForAjax(btnSave, GetLocalResourceObject("GroupNotExist"))
                mpInsert.Show()
                Exit Sub
            End If
        End If

        If gBBL.GroupMemberIsExist(txtCrtGroupID.Text, hiUID.Value, hiDBName.Value) = False Then
            ShowMessageForAjax(btnSave, GetLocalResourceObject("GroupMemberNotExist"))
            mpInsert.Show()
            Exit Sub
        End If
        'If txtURL.Text.Trim = "" Then
        '    ShowMessageForAjax(btnSave, GetLocalResourceObject("URLIsRequired"))
        '    mpInsert.Show()
        '    Exit Sub
        'End If
        If txtSubject.Text.Trim = "" Then
            ShowMessageForAjax(btnSave, GetLocalResourceObject("SubjectIsRequired"))
            mpInsert.Show()
            Exit Sub
        End If

        Try
            DateTime.Parse(txtBegDate.Text)
        Catch ex As Exception
            ShowMessageForAjax(btnSave, GetLocalResourceObject("ErrBegDate"))
            mpInsert.Show()
            Exit Sub
        End Try
        Try
            DateTime.Parse(txtEndDate.Text)
        Catch ex As Exception
            ShowMessageForAjax(btnSave, GetLocalResourceObject("ErrEndDate"))
            mpInsert.Show()
            Exit Sub
        End Try
        '=================================================

        If hiMode.Value = "Ins" Then


            dsBillBoard.Insert()
        Else

            dsBillBoard.Update()
        End If
        gvMain.DataBind()

    End Sub

    Protected Sub btnWF_AdminGroupID_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTargetGroupID.Click

        PopupFormForAjax(btnTargetGroupID, "GroupID,GroupName", GetLocalResourceObject("ChnFieldsName"), "GroupID", hiDBName.Value, "1,2", txtTargetGroupID.ClientID & "," & lblTargetGroupName1.ClientID, "directories=no,location=no,menubar=no,toolbar=no,scrollbars=yes, width=500 ,left=200")
        mpInsert.Show()
    End Sub

    Protected Sub btnCrtGroupID_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCrtGroupID.Click
        PopupFormForAjax(btnTargetGroupID, "GroupID,GroupName", GetLocalResourceObject("ChnFieldsName"), "GroupID", hiDBName.Value, "1,2", txtCrtGroupID.ClientID & "," & txtCrtGroupName.ClientID, "directories=no,location=no,menubar=no,toolbar=no,scrollbars=yes, width=500 ,left=200")
        mpInsert.Show()
    End Sub
End Class
